<script type="text/javascript">
	$(document).ready(function(){
		$.validator.addMethod("correctDate", function(value, element) { 
			return this.optional(element) || /^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(value) || /^\d\d?\.\d\d?\.\d\d\d?\d?$/.test(value); },
			jQuery.format("Please specify the correct date format"));
		
		$.validator.addMethod("phone", function(phone_number, element) {
			phone_number = phone_number.replace(/\s+/g, ""); 
			return this.optional(element) || phone_number.length > 9 &&
			phone_number.match(/^(1-?)?(\([0-9]\d{2}\)|[0-9]\d{2})-?[0-9]\d{2}-?\d{4}$/);},
 			"Please specify a valid phone number");	
		
		$("#addOrder").validate({	
			rules: {
				orderDate : {correctDate : true},
				customerName  : {required: true} ,
				customerCash  : {required: true , number: true},
				customerPhoneNo    : {phone: true}
			},
	 
			messages: {
				//orderDate : {required: 'Required input'},
				customerName  : {required: 'Required input'},
				customerCash  : {required: 'Required input',number : 'cash should be a number'}
		
			}
		});

		
		$('#addOredrItems').validate({
            rules : {
				batchId : { required : true, min : 1},
                itemCode : { required : true},
				orderQuantity: { required : true}
                               
            },
            messages : {
				batchId : { required : ' Please select a batch', min : ' You should select a batch'},
				itemCode : { required : ' Please enter item  code'},
				orderQuantity : { required : ' Please enter item  code'},
				
            }
        });

    });

</script>
<div id="addOrders">	
	<form id="addOrder" name="addOrder" method="POST" action="./system/action/addOrders.php" >
		<fieldset>
			<legend>Order Details</legend>
			<table id="addOrderForm" class="formTable" width="100%">
				<col width="150px"/>
				<col/>
				<tr>
					<td colspan="2">
						<?php
						if(isset($_SESSION['error']) && $_SESSION['error'] != ""){ ?>
							<div class="error">
								<?php echo $_SESSION['error']; ?>
							</div>
						<?php } else if(isset($_SESSION['success']) && $_SESSION['success'] != ""){?>
							<div class="success">
								<?php echo $_SESSION['success']; ?>
							</div>
						<?php }
						?>
					</td>
				</tr>
				<tr>
					<td>Date (yyyy-mm-dd) </td>
					<td><input id="orderDate" name="orderDate" size="25"   /></td>
				</tr>
				<tr>				
					<td>Customer Name<label class="mandatory">*</label></td>
					<td><input id="customerName" name="customerName" size="25" class="required" minlength="2" /></td>
				</tr>
				<tr>				
					<td>Customer Contact No</td>
					<td><input id="customerPhoneNo" name="customerPhoneNo" size="25"  /></td>
				</tr>
				<tr>				
					<td>Customer Cash<label class="mandatory">*</label></td>
					<td><input id="customerCash" name="customerCash" size="25" class="required" /></td>
				</tr>
				
				<tr>
				<td></td>
				<td><input type="submit" value="submit" /></td>
				</tr>
				
			</table>


			
		</fieldset>
		
	</form>

	
	<form name="addOredrItems" id="addOredrItems" method="POST" action="./system/action/addOrderItems.php">
		<fieldset>
			<legend>Order an item</legend>
			<table>	
				<tr>
					<td colspan="2">
						<?php
						if(isset($_SESSION['error']) && $_SESSION['error'] != ""){ ?>
							<div class="error">
								<?php echo $_SESSION['error']; ?>
							</div>
						<?php } else if(isset($_SESSION['success']) && $_SESSION['success'] != ""){?>
							<div class="success">
								<?php echo $_SESSION['success']; ?>
							</div>
						<?php }
						?>
					</td>
				</tr>
				<tr>
					<td>Item code: <label class="mandatory">*</label></td>
					<td> <input type="text" name="itemCode" id="itemCode"></td>
				</tr>
				<tr>
					<td>Batch Id:<label class="mandatory">*</label>  </td>
					<td>
						<select name="batchId" id="batchId">
							<option value="0">Select</option>
							<?php 
								include './system/dbconnection.php';
								if($res = mysql_query(" select * FROM batches")){
									while($row = mysql_fetch_assoc($res)){
										echo "<option value='".$row['batchId']."'>".$row['batchDate']."</option>";
									}
								}
							?>
						</select>
					</td>
				</tr>
				
				<tr>
					<td>Quntity: </td>
					<td><input type="text" name="orderQuantity" id="orderQuantity"></td>
				</tr>
				<tr>
					<td></td>
					<td><input type="submit" name="submit" value="submit"/></td>
				</tr>
			</table>
		</fieldset>
	</form>

</div>